﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;
using System.Security.Principal;
using System.Security.Permissions;

namespace EveruComponent.shell
{
    public class ExplorerExtention
    {
        /// <summary>
        /// Register a new Contextmenu item in the Windows Explorer. You need administrator permission!
        /// </summary>
        /// <param name="Name">The Name and the Title of the Item</param>
        /// <param name="Command">The path to a executable File.</param>
        /// <returns></returns>
        public static bool RegisterContextMenuItem(string Name, string Command)
        {
            
            if(Name.Contains('\\'))
            {
                return false;
            }


            string RegMenuName = "Folder\\shell\\" + Name;
            string RegCommandName = "Folder\\shell\\" + Name +  "\\command";

            RegistryKey regmenu = null;
            RegistryKey regcmd = null;

            try
            {
                regmenu = Registry.ClassesRoot.CreateSubKey(RegMenuName, RegistryKeyPermissionCheck.ReadWriteSubTree);
                if (regmenu != null)
                {
                    regmenu.SetValue("", Name);
                }

                regcmd = Registry.ClassesRoot.CreateSubKey(RegCommandName);
                if (regcmd != null)
                {
                    regcmd.SetValue("", Command);
                }
            }
            catch
            {
                return false;
            }


            return false;
        }







    }
}
